<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <el-upload
          action="/upload"
          name="picFile"
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove">
    <i class="el-icon-plus"></i>
  </el-upload>
  <el-dialog :visible.sync="dialogVisible">
    <img width="100%" :src="dialogImageUrl" alt="">
  </el-dialog>
  <h2>上传图片(成功)</h2>
  <img :src="url" alt="">
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function() {
      return { //在这里面定义变量
        dialogImageUrl: '',
        dialogVisible: false,
        url:""
      }
    },
    methods: {
      handleRemove(file, fileList) {
        console.log(file, fileList);
        //file.response得到的是文件上传成功是服务器响应的内容(图片路径)
        let url = file.response;
        axios.get("/remove?url="+url).then(function (){
          alert("服务器中文件删除成功!");
        })
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleSuccess(response,file,fileList){
        //把服务器响应的图片路径给vue的变量url;
        v.url=response;
      }
    }

  })
</script>
</html>